public class Nquine {
    static int N=20;
    static int n=8;
    static char g[][] = new char[N][N];
    static boolean a[] = new boolean[N];
    static boolean dg[] = new boolean[N];
    static boolean udg[] = new boolean[N];
    public static void main(String[] args) {
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                g[i][j]='.';
            }
        }
        System.out.println(" ");
        dfs(0);

    }
    static void dfs(int u){
        if(u==n){
            for(int i=0;i<n;i++){
                System.out.println(g[i]);
            }
            System.out.println(" ");
            return ;
        }
        for(int i=0;i<n;i++){
            if(!a[i]&&!dg[u+i]&&!udg[n-u+i]){
                g[u][i]='Q';
                a[i]=dg[u+i]=udg[n-u+i]=true;
                dfs(u+1);
                a[i]=dg[u+i]=udg[n-u+i]=false;
                g[u][i]='.';
            }
        }
    }
}
